package com.hph.springcloudsleuthdemo.web.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author HPH
 * @date 2019/7/29
 */
@RestController
public class DemoController {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    private final RestTemplate restTemplate;

    @Autowired
    public DemoController(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    @GetMapping(value = "/index")
    public String index(){

        logger.info("{} index(): {}",getClass(),"index");

        return "index";
    }

    /**
     * (请求方式要和调用的服务一样)
     * spring cloud 大整合
     * 调用路径：spring-sleuth --> spring-zuul --> person client --> person service
     * @return Object
     */
    @GetMapping(value = "/to/zuul/person-client/person/find/all")
    public Object toZuul(){

        logger.info("{} toZuul(): {}",getClass(),"index");

        Object restTemplateForObject  = restTemplate.getForObject("http://spring-cloud-zuul/person-client/person/find/all",Object.class);

        return restTemplateForObject;
    }
}
